<template>
  <div>
    <el-input v-model="oldCertificatNo" :disabled="isDisabled" readonly>
      <i
        v-show="!isDisabled"
        slot="suffix"
        class="el-input__icon el-icon-circle-plus"
        @click="openDia"
      />
      <i v-show="!isDisabled" slot="suffix" class="el-input__icon el-icon-error" @click="changeDE"/>
    </el-input>
    <el-dialog
      ref="dialog"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :visible.sync="dialogFormVisible"
      :append-to-body="true"
      title="三包凭证选择"
      width="75%"
      @opened="searchHandle"
    >
      <div class="searchform">
        <!-- 查询条件 -->
        <el-form
          ref="searchForm"
          :inline="true"
          :model="search"
          size="mini"
          label-width="100px"
          label-position="right"
        >
          <el-form-item prop="certificatNo" label="三包凭证单号">
            <el-input v-model="search.certificatNo" class="search-input"/>
          </el-form-item>
          <div style="text-align:center">
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="searchHandle">查询</el-button>
            </el-form-item>
            <el-form-item>
              <el-button icon="el-icon-refresh" @click="resetForm('searchForm')">重置</el-button>
            </el-form-item>
          </div>
        </el-form>
      </div>
      <div class="table">
        <div class="tableHead">
          <div class="tabletitle">三包凭证信息</div>
        </div>
        <!-- 用户列表 -->
        <BaseTable
          ref="table"
          highlight-current-row
          @chaneg-size="changeSizeHandle"
          @chaneg-page="changePageHandle"
          @current-change="select"
        >
          <el-table-column label="序号" type="index"/>
          <el-table-column label="选择" width="50">
            <template slot-scope="scope">
              <el-radio
                v-model="radioValue"
                :label="scope.$index"
                @change.native="getTemplateRow(scope.$index,scope.row)"
              >&nbsp;</el-radio>
            </template>
          </el-table-column>
          <el-table-column
            :show-overflow-tooltip="true"
            prop="TG_CERTIFICAT_NO"
            label="三包凭证号"
            min-width="150"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="ORDER_NO"
            label="零售合同编号"
            min-width="150"
          />
          <el-table-column :show-overflow-tooltip="true" prop="VIN" label="VIN" min-width="150"/>
          <el-table-column
            :show-overflow-tooltip="true"
            prop="CUSTOMER_CODE"
            label="客户编码"
            min-width="100"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="CUSTOMER_NAME"
            label="客户名称"
            min-width="150"
          />
          <!-- <el-table-column prop="APPLY_TYPE" label="机型" min-width="150" :show-overflow-tooltip="true">
          <template slot-scope="scope">
              <filtercode v-model="scope.row.APPLY_TYPE" type="8011"/>
          </template>
          </el-table-column>-->
          <el-table-column
            :show-overflow-tooltip="true"
            prop="MODEL_NAME"
            label="机型"
            min-width="150"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="PRODUCT_DATE"
            label="生产日期"
            min-width="150"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="SALES_DATE"
            label="销售日期"
            min-width="150"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="FIRST_PRINT_TIME"
            label="首次打印时间"
            min-width="150"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="FIRST_PRINTER"
            label="首次打印人"
            min-width="150"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="PRINT_COUNT"
            label="凭证打印次数"
            min-width="150"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="DEALER_CODE"
            label="销售店代码"
            min-width="150"
          />
          <el-table-column
            :show-overflow-tooltip="true"
            prop="DEALER_NAME"
            label="销售店名称"
            min-width="150"
          />
        </BaseTable>
      </div>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button type="primary" @click="confirmHandle">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { queryCertificatApplyList } from '@/api/repair/basedata/threepack/returnClaim'
import filtercode from '@/components/Checkbox/filtercode'
import BaseTable from '@/components/BaseTable'
import formMixins from '@/mixins/formMixins'
import rSelect from '@/components/Select/Select'
import Radio from '@/components/Radio/Radio'
export default {
  name: 'SelectAppleList',
  components: {
    BaseTable,
    filtercode,
    rSelect,
    Radio
  },
  mixins: [formMixins],
  props: {
    oldCertificatNo: String,
    isDisabled: Boolean
  },
  data() {
    return {
      radioValue: {},
      dialogFormVisible: false,
      multipleSelection: {},
      search: {
        limit: 10,
        pageNum: 1,
        order: 'asc',
        sort: 'APPLY_ID',
        soNo: '',
        customerName: '',
        vin: '',
        isInvoice: 10041002
      }
      // CUSTOMER_NAME: ""
    }
  },

  computed: {},
  mounted() {},
  methods: {
    searchHandle() {
      const table = this.$refs['table']
      queryCertificatApplyList(this.search)
        .then(res => {
          table.complete().filData(res)
        })
        .catch(err => {
          table.complete()
        })
    },
    openDia() {
      this.dialogFormVisible = true
      this.resetForm('searchForm')
      this.multipleSelection = {}
      this.radioValue = {}
      this.searchHandle()
    },
    cancel() {
      this.dialogFormVisible = false
    },
    changeDE() {
      this.$emit('getselectSalesNo', {})
    },
    getTemplateRow(id, rowDate) {
      this.multipleSelection = rowDate
    },
    // 三包换车申请单
    select(val) {
      if (val == null) {
        this.multipleSelection = []
      } else {
        this.multipleSelection = val
      }
    },
    confirmHandle() {
      if (
        this.multipleSelection == null ||
        this.multipleSelection.APPLY_ID == null
      ) {
        this.$message({
          type: 'info',
          message: '请选择数据!'
        })
      } else {
        this.$emit('getselectSalesNo', this.multipleSelection)
        this.dialogFormVisible = false
      }
    }
  }
}
</script>

<style scoped>
.magnifier {
  float: right;
  position: absolute;
  right: 50px;
  top: 23px;
  cursor: pointer;
}
</style>
